package com.kingyea.mobilepolice.apimanage.config;

import com.kingyea.mobilepolice.apimanage.accesscontrol.handle.SecurityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;

/**
 * @author chenjw
 * @version v1.0.0
 * @description
 * @date Created in 2018/4/9 9:14
 */
@Configuration
public class SecurityServiceConfig {
    @Autowired
    private Environment env;

    @Bean(name = "securityService")
    public SecurityService getSecurityService() throws Exception {
        SecurityService ss = new SecurityService();
        ss.setKeyPassword(env.getProperty("kingyea.mobilepolice.apimanage.accesscontrol.jks_KeyPassword"));
        ss.setKeyStoreAlias(env.getProperty("kingyea.mobilepolice.apimanage.accesscontrol.jks_KeyStoreAlias"));
        ss.setKeyStore(env.getProperty("kingyea.mobilepolice.apimanage.accesscontrol.jks_KeyStore"));
        ss.setKeyStorePassword(env.getProperty("kingyea.mobilepolice.apimanage.accesscontrol.jks_KeyStorePassword"));
        ss.setTrustStorePassword(env.getProperty("kingyea.mobilepolice.apimanage.accesscontrol.jks_TrustStorePassword"));
        ss.setTrustStore(env.getProperty("kingyea.mobilepolice.apimanage.accesscontrol.jks_TrustStore"));
        ss.setTrustStoreAlias(env.getProperty("kingyea.mobilepolice.apimanage.accesscontrol.jks_TrustStoreAlias"));
        ss.init();
        return ss;
    }
}
